home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / headers / flowsettings.h < prev    next >
C/C++ Source or Header  |  1995-09-29  |  5KB  |  190 lines

  1. #pragma once
  2. //
  3. // flowsettings: a simple way to read and write flow parameters
  4. //
  5. class flowsettings
  6. {
  7.     public:
  8.         double translation_x;
  9.         double translation_y;
  10.         double expansion;
  11.         double rotation;            // in degrees per second
  12.         double shear_magnitude;
  13.         double shear_direction;        // in degrees
  14.         
  15.         flowsettings();
  16.         void init();
  17.         
  18.         int is_translation_free() const;
  19.         int is_rotation_free() const;
  20.         int is_expansion_free() const;
  21.         int is_shear_free() const;
  22.         int is_unity() const;
  23.  
  24.         int operator==( const flowsettings &that) const;
  25.  
  26.     friend ostream& operator<<( ostream& destroom,
  27.                                 const flowsettings &thesettings);
  28.  
  29.     friend istream& operator>>( istream& destroom, flowsettings &thesettings);    
  30. };
  31. //
  32. // flowexpsettings effectively contains three settings; the first is the
  33. // reference flow, the second and third contain the starting and ending point
  34. // of the 'trajectory' alongside which testing takes place.
  35. // Note that usually, point_zero will equal the reference flow. We allow
  36. // these to differ because we migth wish to ask for instance:
  37. // 'which one rotates faster', where the reference flow is rotating and
  38. // expanding, whereas the test flows are only rotating.
  39. // The 'distance' between 'point_zero' and 'point_one' determines the 'unit'.
  40. //
  41. class flowexpsettings : public flowsettings
  42. {
  43.     public:
  44.         flowsettings point_zero;
  45.         flowsettings point_one;
  46.         
  47.         flowexpsettings();
  48.         
  49.         void getvalue( flowsettings *new_value, const double lambda);
  50.         //
  51.         // the ..._does_change members return true whenever the relevant
  52.         // parts of point_zero and/or point_one differ.
  53.         //
  54.         int dx_does_change() const;
  55.         int dy_does_change() const;
  56.         int translation_does_change() const;
  57.         int exp_does_change() const;
  58.         int rot_does_change() const;
  59.         int mag_does_change() const;
  60.         int dir_does_change() const;
  61.         int shear_does_change() const;
  62.         
  63.     friend ostream& operator<<( ostream& destroom,
  64.                         const flowexpsettings &thesettings);
  65.  
  66.     friend istream& operator>>( istream& destroom,
  67.                         flowexpsettings &thesettings);
  68.     //
  69.     // The advantage of 'shorthand_out' and 'longhand_out' over
  70.     // "ostream &operator>>" is that they are better suited for import of the
  71.     // data into a spreadsheet.
  72.     //
  73.     // Use 'shorthand_out' to write the settings in a non-recoverable format
  74.     // 'shorthand_out' can be a convenient format for importing into a
  75.     // spreadsheet, but the number of columns produced by 'shorthand_out'
  76.     // varies with the number of varying parameters in the flowexpsettings.
  77.     // 
  78.     // 'longhand_out' is a similar format, but with a fixed number of columns.
  79.     //
  80.     // If I knew how to do it, I would possibly implement this with an IOStream
  81.     // manipulator.
  82.     //
  83.     // The flag 'force_three' is used to indicate that 'point_zero' should
  84.     // also be output when it is equal to the reference flow.
  85.     //
  86.     void shorthand_out( ostream &destroom = cout, int force_three = false) const;
  87.     void longhand_out( ostream &destroom = cout, int force_three = false) const;
  88.     
  89.     private:
  90.         static double lin_interpolate( double start, double end, double lambda);
  91.         static double log_interpolate( double start, double end, double lambda);
  92. };
  93.  
  94. inline void flowsettings::init()
  95. {
  96.     translation_x   = 0.0;
  97.     translation_y   = 0.0;
  98.     expansion       = 1.0;
  99.     rotation        = 0.0;
  100.     shear_magnitude = 1.0;
  101.     shear_direction = 0.0;
  102. }
  103.  
  104. inline flowsettings::flowsettings()
  105. {
  106.     init();
  107. }
  108.  
  109. inline int flowsettings::is_translation_free() const
  110. {
  111.     return ((translation_x == 0.0) && (translation_y == 0.0));
  112. }
  113.  
  114. inline int flowsettings::is_rotation_free() const
  115. {
  116.     return (rotation == 0.0);
  117. }
  118.  
  119. inline int flowsettings::is_expansion_free() const
  120. {
  121.     return (expansion == 1.0);
  122. }
  123.  
  124. inline int flowsettings::is_shear_free() const
  125. {
  126.     return (shear_magnitude == 1.0);
  127. }
  128.  
  129. inline int flowsettings::is_unity() const
  130. {
  131.     return ( is_translation_free() &&
  132.         is_expansion_free() && is_rotation_free() &&
  133.         is_shear_free() && (shear_direction == 0.0)
  134.     );
  135. }
  136.  
  137. inline flowexpsettings::flowexpsettings() : flowsettings()
  138. {
  139.     point_zero.init();
  140.     point_one.init();
  141. }
  142.  
  143. inline double flowexpsettings::lin_interpolate(
  144.             double start, double end, double lambda)
  145. {
  146.     return (1.0 - lambda) * start + lambda * end;
  147. }
  148.  
  149. inline double flowexpsettings::log_interpolate(
  150.             double start, double end, double lambda)
  151. {
  152.     return exp( (1.0 - lambda) * log( start) + lambda * log( end));
  153. }
  154.  
  155. inline int flowexpsettings::dx_does_change() const
  156. {
  157.     return ((translation_x != point_one.translation_x)
  158.                 || (translation_x != point_zero.translation_x));
  159. }
  160.  
  161. inline int flowexpsettings::dy_does_change() const
  162. {
  163.     return ((translation_y != point_one.translation_y)
  164.                 || (translation_y != point_zero.translation_y));
  165. }
  166.  
  167. inline int flowexpsettings::exp_does_change() const
  168. {
  169.     return ((expansion != point_one.expansion)
  170.                 || (expansion != point_zero.expansion));
  171. }
  172.  
  173. inline int flowexpsettings::rot_does_change() const
  174. {
  175.     return ((rotation != point_one.rotation)
  176.                 || (rotation != point_zero.rotation));
  177. }
  178.  
  179. inline int flowexpsettings::mag_does_change() const
  180. {
  181.     return ((shear_magnitude != point_one.shear_magnitude)
  182.                 || (shear_magnitude != point_zero.shear_magnitude));
  183. }
  184.  
  185. inline int flowexpsettings::dir_does_change() const
  186. {
  187.     return ((shear_direction != point_one.shear_direction)
  188.                 || (shear_direction != point_zero.shear_direction));
  189. }
  190.